﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
using Webdiver;

namespace AnyOffice.general.rms.roll_stat
{
    public partial class index : ModulePage
    {
        public void ChangePage(object src, PageChangedEventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            this.BindData();
        }
        private void BindData()
        {
            DataTable table = new RmsRollDao().SelectPaged(base.Conn, this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, false);
            this.ViewState["CurrentRowNums"] = table.Rows.Count;
            this.ViewState["CurrentPage"] = this.AspNetPager1.CurrentPageIndex.ToString();
            this.rptRmsRoll.DataSource = table;
            this.rptRmsRoll.DataBind();
            this.litNavCount.Text = "<span class=\"small1\">共&nbsp;<span class=\"big4\">" + this.AspNetPager1.RecordCount.ToString() + "</span>&nbsp;条";
            this.litNavPager.Text = "<span class=\"small1\">当前为第" + this.AspNetPager1.CurrentPageIndex.ToString() + "页，共" + this.AspNetPager1.PageCount.ToString() + "页，每页最多" + this.AspNetPager1.PageSize.ToString() + "条</span>";
        }
 

        public string GetCodeName(string codeId, string codeType)
        {
            if (codeType == "Secret")
            {
                return new RmsCodeDao().GetCodeName(base.Conn, codeId, RmsCodeDao.CodeType.Secret);
            }
            if (codeType == "CertificateKind")
            {
                return new RmsCodeDao().GetCodeName(base.Conn, codeId, RmsCodeDao.CodeType.CertificateKind);
            }
            return string.Empty;
        }
        public int GetFileNums(int rollId)
        {
            return new RmsRollDao().GetFileNums(base.Conn, rollId);
        } 

 

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                DataTable table = new RmsRollDao().SelectPaged(base.Conn, this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, true);
                if (int.Parse(table.Rows[0][0].ToString()) == 0)
                {
                    this.litNavCount.Visible = false;
                    this.litNavPager.Visible = false;
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowMessage("无案卷");
                }
                else
                {
                    this.AspNetPager1.RecordCount = int.Parse(table.Rows[0][0].ToString());
                    this.BindData();
                }
            }
            if (this.Page.IsPostBack)
            {
                int num = 0;
                RmsRollDao dao2 = new RmsRollDao();
                foreach (RepeaterItem item in this.rptRmsRoll.Items)
                {
                    HtmlInputCheckBox box = (HtmlInputCheckBox)item.FindControl("RollId");
                    if ((box != null) && box.Checked)
                    {
                        dao2.Delete(base.Conn, int.Parse(box.Value));
                        num++;
                    }
                }
                if (num == Convert.ToInt32(this.ViewState["CurrentRowNums"].ToString()))
                {
                    DataTable table2 = dao2.SelectPaged(base.Conn, this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, true);
                    this.AspNetPager1.RecordCount = int.Parse(table2.Rows[0][0].ToString());
                    if (int.Parse(table2.Rows[0][0].ToString()) == 0)
                    {
                        this.pnlMain.Visible = false;
                        this.litNavCount.Visible = false;
                        this.litNavPager.Visible = false;
                        this.litMessage.Text = base.ShowMessage("无已发布的案卷");
                    }
                    else
                    {
                        if (this.AspNetPager1.CurrentPageIndex > 1)
                        {
                            this.AspNetPager1.CurrentPageIndex--;
                        }
                        this.BindData();
                    }
                }
            }


        }
    }
}
